package com.view;

import com.essential.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.media.MediaPlayer;
import android.view.View;

public class CustomView extends View {

	Context ctx;
	Paint lPaint = new Paint();
	int x_1 = 0, y_1 = 0;
	MediaPlayer player = null;
	Bitmap ball = null;
	boolean running = true;

	public CustomView(Context context) {
		super(context);

		player = MediaPlayer.create(context, R.raw.lotus);
		BitmapDrawable d = (BitmapDrawable) getResources().getDrawable(
				R.drawable.ball_bmp);
		ball = d.getBitmap();
		ctx = context;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		Rect rct = new Rect();
		rct.set(0, 0, canvas.getWidth(), canvas.getHeight());
		Paint pnt = new Paint();
		pnt.setStyle(Paint.Style.FILL);
		pnt.setColor(Color.WHITE);
		canvas.drawRect(rct, pnt);
		x_1 += 2;
		y_1 += 2;
		if (x_1 >= canvas.getWidth()) {
			x_1 = 0;
			y_1 = 0;
		}
		drawSprint(x_1, y_1, canvas);

		drawSprint(canvas.getWidth() - x_1, y_1, canvas);

		if (running)
			invalidate();
	}

	protected void drawSprint(int x, int y, Canvas canvas) {
		canvas.drawBitmap(ball, x, y, lPaint);
	}

}
